package com.xpec.c4.service.module.datacenter.account;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.service.module.account.db.AccountDAO;
import com.xpec.c4.game.datamanager.ResultNo;
import com.xpec.c4.service.module.datacenter.DCAsyncCommand;

/**
 * 
 * @author yangbingyan
 *
 */
public class LoadAccountDataAsync extends DCAsyncCommand{

	
	/**
	 * 
	 */
	protected AccountDataManager dataManager;
	
	/**
	 * 
	 */
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(LoadAccountDataAsync.class);
	
	
	@Override
	public void asyncExecute() {		
	
		dataInfo.setData(null);
	
		try{
			dataInfo.setData( AccountDAO.loadAccountByAccountId(dataInfo.getKey()));
			
			if (dataInfo.getData() != null) {
				resultCode = ResultNo.OK;
			} else {
				resultCode = ResultNo.DATA_NOT_FOUND;
			}
			
		}catch(Exception e){
			resultCode = ResultNo.DB_OPERATION_FAILED;
		}

		return;
	}

	@Override
	public void execute() {
		// callback
		if (dataManager != null) {
			dataManager.readDataCallback(resultCode, dataInfo, srcModuleID,
					dataInfo.getData(), true);
		}
	}

	public void setDataManager(AccountDataManager dataManager) {
		this.dataManager = dataManager;
	}

}
